#include "requirePackage.h"
#include "sampleSys_def.h"

requirePackage::requirePackage() {
	random = 0;
	memset(devId, 0, sizeof(devId));
	memset(passwd, 0, sizeof(passwd));
}

requirePackage::~requirePackage() {
}

void requirePackage::inbody(char* buffer) {
	
	//strcpy_s((char*)passwd, sizeof(passwd), buffer);
	memcpy_s(passwd, sizeof(passwd), buffer, sizeof(passwd));
	strcpy_s((char*)devId, sizeof(devId), buffer + 16);
	random = *((unsigned int*)(buffer + 48));

	printData();
}

unsigned char* requirePackage::getDevIdValue() {
	return devId;
}

bool requirePackage::decipherPas() {
	int* passiwd = (int*)passwd;
	for (int i = 3; i >= 1; i--) {
		passiwd[i] = passiwd[i] ^ passiwd[i - 1];
	}
	passiwd[0] = passiwd[0] ^ random;
	if (strcmp((const char*)passwd, TRUE_PASSWD) == 0) {
		return true;
	}
	else {
		return false;
	}
}

void requirePackage::printData() {
	printf_s("rand = %lld\n devId = %s\n passwd = %s\n", rand, devId, passwd);
}